package com.easybuy.controller;

import com.easybuy.Tools.Page;
import com.easybuy.pojo.News;
import com.easybuy.pojo.User;
import com.easybuy.service.NewsSerivce.NewsSerivce;
import com.ndktools.javamd5.Mademd5;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
//对于新闻的操作
public class Member_NewsController {
    @Autowired
    NewsSerivce newsSerivce;

    @RequestMapping("/newsList")
    @ResponseBody
    //获取所有新闻（分页）
    public Page newsList(Page page){
        return newsSerivce.newsList(page);
    }


    @RequestMapping("/getNews")
    @ResponseBody
    //通过id查询单个新闻
    public News getNews(@RequestParam int id){
        return newsSerivce.getNews(id);
    }


    @RequestMapping("/addNews")
    @ResponseBody
    //添加新闻
    public Boolean addNews(News news){
        if(newsSerivce.addNews(news)>0){
            return true;
        }else {
            return false;
        }
    }


    @RequestMapping("/modifyNews")
    @ResponseBody
    //修改新闻
    public boolean modifyNews(News news){
        if (newsSerivce.modifyNews(news)>0){
            return true;
        }
        else return false;
    }


    @RequestMapping("/deleNews")
    @ResponseBody
    //删除新闻
    public boolean deleNews(int id){
        if (newsSerivce.deleNews(id)>0){
            return true;
        }
        else return false;
    }
}
